﻿using System;
using System.Collections.Generic;
using Sharp.Platform.Other;

namespace Sharp.Platform.List
{
    /// <summary>
    /// 工具栏按钮中介
    /// </summary>
    public class ToolButtonOperateAction
    {
        private readonly Dictionary<string, Func<ToolButtonInfo, string>> _operateDictionary = new Dictionary<string, Func<ToolButtonInfo, string>>();
        public ToolButtonOperateAction()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public ToolButtonOperateAction(string operate)
        {
            
        }

        public void GatherOperate(string operate, Func<ToolButtonInfo, string> action)
        {
            if (!_operateDictionary.ContainsKey(operate))
                _operateDictionary.Add(operate, action);
        }
        /// <summary>
        /// 执行具体实现的代码
        /// </summary>
        /// <param name="operate"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public string ExecuteOperate(string operate, ToolButtonInfo param)
        {
            if (_operateDictionary.ContainsKey(operate))
            {
                return _operateDictionary[operate](param);
            }
            else
            {
                return _operateDictionary["Custom"](param);
            }
        }

    }
}
